var WASP_MENU_BTN_AUTH_CREATE = function () {
	var $pageList = "";
	var buttonMap = {};
	/**
	 * 初始化jqgrid表单对象
	 */
	this.Init = function (pageListDivId) {
		if (pageListDivId instanceof jQuery) {
			$pageList = pageListDivId;
		} else if (pageListDivId.indexOf("#") == 0) {
			$pageList = $(pageListDivId);
		} else {
			$pageList = $("#" + pageListDivId);
		}
		return null;
	};
	/**
	 * 添加onClick事件
	 */ 
	this.addOnclick = function (temp, func, element) {
		var $element = element || "a";
		$("#"+ temp + " " + $element).removeAttr("disabled");
		$("#"+ temp + " " + $element).attr("onclick", func);
		buttonMap[temp] = $("#" + temp).html();
	};
	/**
	 * 移除onClick事件
	 */ 
	this.removeOnclick = function (temp, element) {
		var $element = element || "a";
		$("#" + temp + " " + $element).attr("disabled", "disabled");
		$("#" + temp + " " + $element).removeAttr("onclick");
		buttonMap[temp] = $("#" + temp).html();
	};
	/**
	 * 获取按钮html
	 */
	this.getButton = function (temp) {
		return buttonMap[temp];
	};
	/**
	 * 校验是否有按钮的操作权限（操作栏）
	 * 用于控制是否显示按钮
	 */
	this.checkBtnAuth = function (resourceId, btnId, temp, element) {
		var btnName = "";
		var btnMap = {};
		if ($pageList && resourceId) {
			var permissionResult = $pageList.getGridParam('userData');
			if (!jQuery.isEmptyObject(permissionResult)) {
				btnMap = permissionResult[resourceId];
				if (btnMap) {
					btnName = btnMap[btnId];
				}
			}
		}
		if (btnName != null && btnName != "") {
			this.removeOnclick(temp, element);
			return true;
		} else {
			buttonMap[temp] = "";
			return false;
		}
	};
	// 批量权限校验
	this.checkBatchBtnAuth = function (resourceIds, btnId) {
		var dataMap =  new AUIMap();
		if (resourceIds instanceof Array) {
			for (var i = 0; i < resourceIds.length; i++){
				var btnName = this.checkBtnAuth(resourceIds[i], btnId);
				if (btnName != null || btnName != "") {
					var rowData = $pageList.jqGrid('getRowData', resourceIds[i]);
					dataMap.set(resourceIds[i], rowData);
				}
			}
		}
		return dataMap;
	};
};

/**
 * 查询菜单ID
 */
function getMenuId() {
	var currentHref = location.href;
	var menuId = "";
	$(top.document.getElementsByTagName("iframe")).each(function (index, obj) {
		if (obj.src == currentHref) {
			menuId = $(obj).attr("data-id");
		};
	});
	return menuId;
}

$(function () {
	$.ajaxSetup({
		//设置ajax请求结束后的执行动作
	    complete :
	        function(XMLHttpRequest, textStatus) {
	            var status = XMLHttpRequest.status;
	            if (status == "403") {
	                window.location = XMLHttpRequest.getResponseHeader("CONTEXTPATH");
	            }
	        }
	});
});